{extend name="../public/header" /}
{block name="body"}
<body>
{include file="../public/top" uname="$roleInfo.uname" lv="$roleInfo.ulv" ls="$roleInfo.uyxb" jp="$roleInfo.uczb" /}
<div class="subject main">
	<div class="layui-row">
		<div class="content">
			<div class="current">
				<span class="position">{$roleInfo.map.mname}</span>
				<span class="state ajax-goto" data-url="{:url('index')}">{if $roleInfo.map.ispvp==0}[安全区]{else/}[PVP]{/if}</span>
				<a class="info" href="javascript:history.go(-1)">返回</a>
			</div>
			<div class="npc">
				<div class="layui-card">
					<div class="layui-card-header">[Lv:{$info.rwlv}] {$info.rwname} <span class="nickname"><{$info.rwlxName}></span></div>
					<div class="layui-card-body">{$info.rwinfo|default=''}</div>
				</div>
				<div class="layui-card">
					<div class="layui-card-header">要求</div>
					<div class="layui-card-body">请
						{if $info.rwzl==1}【收集】 {$info.rwyq_name} x {$info.rwcount}{/if}
						{if $info.rwzl==2}【杀死】 {$info.rwyq_name} x {$info.rwcount}{/if}
						{if $info.rwzl==3}【找到】 {$info.rwcount_name}{/if}
					</div>
				</div>
				<div class="layui-panel">
					<input type="hidden" id="npc_id" name="npc_id" value="{$info.npc_id|default='0'}">
					{if $info.status==1}
					<a class="layui-btn layui-btn-fluid ajax-set" data-url='{:url("setTask")}' data-status="{$info.status}" data-task="{$info.rwid}" data-mytask="{$info.task_id_my}">接取</a>
					{/if}
					{if $info.status==2}
					<a class="layui-btn layui-btn-fluid ajax-set" data-url='{:url("setTask")}' data-status="{$info.status}" data-task="{$info.rwid}" data-mytask="{$info.task_id_my}">提交</a>
					{/if}
					{if $info.status==3}
					<a class="layui-btn layui-btn-fluid layui-btn-disabled">未完成</a>
					{/if}
				</div>
			</div>
		</div>
	</div>
</div>
</body>
{/block}
{block name="script"}
<script>
	layui.use(['jquery', 'form', 'layajax', 'upload', 'flow', 'element'], function () {
		var $ = layui.jquery
				, layajax = layui.layajax
				, upload = layui.upload
				, element = layui.element
				, flow = layui.flow
				, form = layui.form;

		$('.ajax-set').on('click', function () {
			var obj = $(this);
			var url = obj.data('url');
			var status = obj.data('status');
			var task = obj.data('task');
			var mytask = obj.data('mytask');
			var npc_id = $('#npc_id').val();

			console.log('url', url);

			var map = {};
			map['status'] = status;
			map['rwid'] = task;
			map['task_id_my'] = mytask;
			map['npc_id'] = npc_id;

			$.post(url, map, function (res) {
				if (res.code == undefined) {
					console.log('res为json字符串', res);
					res = JSON.parse(res);
				} else {
					console.log('res为json对象', res);
				}
				if (res.code == 1) {
					layer.msg(res.msg, {time:2000}, function(index){
						window.location.href = res.data.url;
					});
				} else {
					layer.msg(res.msg);
				}
			});
		});

		form.render();
	});
</script>
{/block}
